package com.wxzz.elearing.user.api.docent;

import com.alibaba.fastjson.JSONObject;
import com.wxzz.elearing.user.dto.DocentDto;
import com.wxzz.elearing.user.dto.DocentInsDto;
import com.wxzz.elearing.user.dto.DocentToolDto;
import com.wxzz.elearing.user.dto.DocentTrialDto;
import com.wxzz.elearing.user.entity.Docent;
import com.wxzz.elearing.user.entity.DocentTool;
import com.wxzz.elearing.user.entity.DocentTrial;
import com.wxzz.elearing.user.service.IDocentService;
import com.wxzz.elearning.common.exception.ServiceException;
import com.wxzz.elearning.common.vo.JgPageVo;
import com.wxzz.elearning.common.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/docent-docent")
@Api(tags = "讲师接口(讲师端)")
public class DocentDocentController {

    @Autowired
    private IDocentService docentService;

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @ApiOperation(value = "发布或修改试讲试讲(讲师端)", notes = " 发布或修改试讲试讲(讲师端)", httpMethod = "POST", tags = "讲师端")
    @RequestMapping(value = "docentSaveDocentTrial", method = RequestMethod.POST)
    public ReturnVO docentSaveDocentTrial(@RequestHeader String token, @RequestBody DocentTrial docentTrial) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        docentTrial.setDocentId(jsonObject.getLong("docentId"));
        return docentService.saveDocentTrial(docentTrial);
    }

    @ApiOperation(value = " 试讲列表(讲师端)", notes = " 试讲列表(讲师端)", httpMethod = "POST", tags = "讲师端")
    @RequestMapping(value = "listDocentTrial", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<DocentTrial>>> listDocentTrial(@RequestHeader String token, @RequestBody DocentTrialDto docentTrialDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        docentTrialDto.setDocentId(jsonObject.getLong("docentId"));
        return docentService.listDocentTrial(0, docentTrialDto);
    }

    @ApiOperation(value = "晋升列表(讲师端)", notes = " 试讲列表(讲师端)", httpMethod = "POST", tags = "讲师端")
    @RequestMapping(value = "listPromotion", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<DocentTrial>>> listPromotion(@RequestHeader String token, @RequestBody DocentTrialDto docentTrialDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        docentTrialDto.setDocentId(jsonObject.getLong("docentId"));
        return docentService.listDocentTrial(1, docentTrialDto);
    }

    @ApiOperation(value = "试讲发布至晋升(讲师端)", notes = "试讲发布至晋升(讲师端)", httpMethod = "POST", tags = "讲师端")
    @RequestMapping(value = "sendDocentTrialToPromotion/{docentTrialId}", method = RequestMethod.POST)
    public ReturnVO sendDocentTrialToPromotion(@PathVariable Long docentTrialId) {
        return docentService.sendDocentTrialToPromotion(docentTrialId);
    }

    @ApiOperation(value = " 修改讲师介绍(讲师端)", notes = " 修改讲师介绍(讲师端)", httpMethod = "POST", tags = "讲师端")
    @RequestMapping(value = "updateDocentDetail", method = RequestMethod.POST)
    public ReturnVO updateDocentDetail(@RequestHeader String token, @RequestBody Docent docent) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        docent.setId(jsonObject.getLong("docentId"));
        return docentService.updateDocentDetail(docent);
    }


//    @ApiOperation(value = "展示我的账户(讲师端)", notes = "展示我的账户(讲师端)", httpMethod = "POST", tags = "讲师端")
//    @RequestMapping(value = "selectMyWallet", method = RequestMethod.POST)
//    public ReturnVO<Docent> selectMyWallet(@RequestHeader String token) {
//        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
//        return docentService.selectMyWallet(jsonObject.getLong("docentId"));
//    }

}
